package org.glut.controller;

import org.glut.bean.CFAir;
import org.glut.service.CFAirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 厨房燃气controller
 * @author 啊林
 * @date 2022/1/9
 * @time 16:04
 */
@Controller
public class CFController {
    @RequestMapping("/cfline")
    public String cfline(){
        return "/myviews/cfline";
    }

    @RequestMapping("/cfpower")
    public String cfpower(){
        return "/myviews/cfpower";
    }

    @Autowired
    private CFAirService cfAirService;

    /**
     * 获取厨房燃气bean
     * @return
     */
    @RequestMapping("/getCF")
    @ResponseBody
    public CFAir getCF(String id) {
        if ("1".equals(id)) {
            return CFAirService.cfAir1;
        }else{
            return CFAirService.cfAir2;
        }
    }

    /**
     * 发命令控制厨房燃气
     * @return
     */
    @RequestMapping("/sendCF")
    @ResponseBody
    public boolean sendCF(String num,String auto,String status,String id) {
        cfAirService.setCmd(num,auto,status,id);
        return true;
    }

    /**
     * 获取厨房燃气上传时间List
     * @return
     */
    @RequestMapping("/getcfTimeDate")
    @ResponseBody
    public List<String> getcfTimeDate(String id){
        List<String> timeList;
        if ("1".equals(id)) {
            timeList = cfAirService.cftimeList1;
        }else {
            timeList = cfAirService.cftimeList2;
        }
        if (timeList.size() > 30) {
//            List<String> list = timeList.subList(timeList.size() - 30, timeList.size() - 1);
//            cfAirService.timeList.remove(0);
//            cfAirService.timeList = new ArrayList<>(list);
            timeList.remove(0);
        }
        return timeList;
    }

    /**
     * 获取厨房燃气上传浓度List
     * @return
     */
    @RequestMapping("/getcfNumDate")
    @ResponseBody
    public List<String> getcfNumDate(String id){
        List<String> cfList ;
        if ("1".equals(id)) {
            cfList = cfAirService.cfnumList1;
        }else {
            cfList = cfAirService.cfnumList2;
        }
        if (cfList.size() > 30) {
//                List<String> list = cfList.subList(cfList.size() - 30, cfList.size() - 1);
//                cfAirService.cfList = new ArrayList<>(list);
            int size = cfList.size();
           cfList = cfList.subList(size-30,size);
        }
        return cfList;
    }

    /**
     * 获取厨房燃气上传电量List
     * @return
     */
    @RequestMapping("/getcfpowerDate")
    @ResponseBody
    public List<String> getcfpowerDate(String id){
        List<String> cfList;
        if ("1".equals(id)) {
            cfList = cfAirService.cfpower1;
        }else {
            cfList = cfAirService.cfpower2;
        }
        if (cfList.size() > 30) {
//                List<String> list = cfList.subList(cfList.size() - 30, cfList.size() - 1);
//                cfAirService.cfList = new ArrayList<>(list);
            int size = cfList.size();
            cfList = cfList.subList(size-30,size);
        }
        return cfList;
    }

}
